package com.zero.mxshengadmin.modules.website.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.zero.mxshengadmin.common.exception.RRException;
import com.zero.mxshengadmin.common.utils.PageUtils;
import com.zero.mxshengadmin.common.utils.Query;
import com.zero.mxshengadmin.modules.website.dao.WebsiteAdvertiseDao;
import com.zero.mxshengadmin.modules.website.entity.WebsiteAdvertiseEntity;
import com.zero.mxshengadmin.modules.website.service.WebsiteAdvertiseService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by aicaikeji on 2019/4/3.
 */
@Service("websiteAdvertiseService")
public class WebsiteAdvertiseServiceImpl extends ServiceImpl<WebsiteAdvertiseDao,WebsiteAdvertiseEntity> implements WebsiteAdvertiseService {

    @Override
    public void save(WebsiteAdvertiseEntity entity) {
        boolean save = this.insert(entity);
        if (!save) throw new RRException("操作失败");
    }

    @Override
    public WebsiteAdvertiseEntity getById(long id) {
        WebsiteAdvertiseEntity entity = this.selectById(id);
        if (entity == null) {
            throw  new RRException("操作失败");
        }else {
            return entity;
        }
    }

    @Override
    public void update(WebsiteAdvertiseEntity entity) {
        boolean update = this.updateById(entity);
        if (!update) throw new RRException("操作失败");
    }

    @Override
    public void removeByIds(Long[] ids) {
        this.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {

        Page<WebsiteAdvertiseEntity> page = this.selectPage(
                new Query<WebsiteAdvertiseEntity>(params).getPage(),
                new EntityWrapper<>()
        );

        return new PageUtils(page);
    }
}
